package org.apache.struts2.osgi;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;

import org.osgi.framework.Bundle;

import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;

public class OsgiFileManagerFactory implements FileManagerFactory {
	private Bundle bundle;
	@Override
	public void setReloadingConfigs(String reloadingConfigs) {
		System.out.println(reloadingConfigs);

	}

	@Override
	public FileManager getFileManager() {
		return new FileManager() {
			
			@Override
			public boolean support() {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void setReloadingConfigs(boolean reloadingConfigs) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public URL normalizeToFileProtocol(URL url) {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public void monitorFile(URL fileUrl) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public InputStream loadFile(URL fileUrl) {
				try {
					return fileUrl.openStream();
				} catch (IOException e) {
					e.printStackTrace();
				}
				return null;
			}
			
			@Override
			public boolean internal() {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public Collection<? extends URL> getAllPhysicalUrls(URL url)
					throws IOException {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public boolean fileNeedsReloading(URL fileUrl) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean fileNeedsReloading(String fileName) {
				return false;
			}
		};
	}

	public Bundle getBundle() {
		return bundle;
	}

	public void setBundle(Bundle bundle) {
		this.bundle = bundle;
	}
}
